﻿using AutoMapper;
using MediatR;
using S.BreedingHistory.Api.Application.Commmand;
using S.BreedingHistory.Domain.Model;
using S.BreedingHistory.Infrastructure.Interface;

namespace S.BreedingHistory.Api.Application.CommmandHandler
{
    public class BreedHistoryUpdateCommandHandler : IRequestHandler<BreedHistoryUpdateCommand, bool>
    {
        private readonly IBreedingHistoryRepository breedingHistoryRepository;
        private readonly IMapper mapper;

        public BreedHistoryUpdateCommandHandler(IBreedingHistoryRepository breedingHistoryRepository,IMapper mapper)
        {
            this.breedingHistoryRepository = breedingHistoryRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 种母历史记录的修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<bool> Handle(BreedHistoryUpdateCommand request, CancellationToken cancellationToken)
        {
            BreedingHistoryModel breedingHistoryModel=mapper.Map<BreedingHistoryModel>(request);
            return breedingHistoryRepository.UpdateAsync(breedingHistoryModel);
        }
    }
}
